<%--
  Created by IntelliJ IDEA.
  User: Lanan
  Date: 2017/12/26 0026
  Time: 15:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<html>
<head>
    <%--<%@ include file="/commons/basejs.jsp" %>--%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>微信公众号首页Menu</title>
</head>
<body>
<style type="text/css">
    .grid{
        font:12px arial,helvetica,sans-serif;
        border: 0px solid #8DB2E3;width:100%;
        border-collapse:collapse;
    }
    .grid td{
        font:100% arial,helvetica,sans-serif;
        /*text-align: center;*/
        height:30px;
        border:1px solid #e0e0e0;
        padding-left:5px}
</style>
<form id="insertContentForm" action="" method="post">
    <table width="100%" class="grid">
        <tr style="height: 10px"></tr>
        <tr>
            <td align="right" width="35%"><label>菜单名称:</label></td>
            <td align="left"  width="65%"><input class="easyui-validatebox" name="name" data-options="missingMessage:'请输入菜单名称',required:true"></td>
        </tr>
        <tr>
            <td align="right"><label>菜单类型:</label></td>
            <td align="left">
                <select id="select_menu_type" name="type" class="easyui-combobox" data-options="width:130,editable:false,panelHeight:'auto'">
                    <option value="" selected="selected">无类型一级菜单</option>
                    <option value="view">页面</option>
                    <option value="click">按钮</option>
                    <option value="miniprogram">小程序</option>
                    <option value="scancode_waitmsg">扫码待提示</option>
                    <option value="scancode_push">扫码推事件</option>
                    <option value="pic_sysphoto">系统拍照发图</option>
                    <option value="pic_photo_or_album">拍照或者相册发图</option>
                    <option value="pic_weixin">微信相册发图</option>
                    <option value="location_select">发送位置</option>
                    <option value="media_id">图片</option>
                    <option value="view_limited">图文消息</option>
                </select>
                &nbsp;&nbsp;&nbsp;<label id="showCanSetSubMenu"></label>
            </td>
        </tr>
        <tr id="parent_menu_td">
            <td align="right"><lable for="parentid">上级菜单:</lable></td>
            <td>
                <select id="insert_manu_select" name="parentid" style="width:130px;"></select>
                <a class="easyui-linkbutton" href="javascript:void(0)" onclick="$('#insert_manu_select').combotree('clear');$('#insert_manu_select').combotree('setValue', '');" >清空</a>
            </td>
        </tr>
        <tr id="menu_key_td">
            <td align="right"><label>菜单key:</label></td>
            <td align="left"><input id="menu_key_validatebox" class="easyui-validatebox" name="k" data-options="missingMessage:'请输入菜单key',required:true"></td>
        </tr>
        <tr id="menu_mediaId_td">
            <td align="right"><label>media_id:</label></td>
            <td align="left"><input id="menu_mediaId_validatebox" class="easyui-validatebox" name="mediaId" data-options="missingMessage:'请输入media_id',required:true"></td>
        </tr>
        <tr id="menu_url_td">
            <td align="right"><label>跳转链接:</label></td>
            <td align="left"><input id="menu_url_validatebox" class="easyui-validatebox" name="url" data-options="missingMessage:'请输入跳转链接',required:true"></td>
        </tr>
        <tr id="menu_appid_td">
            <td align="right"><label>小程序APPID:</label></td>
            <td align="left"><input id="menu_appid_validatebox" class="easyui-validatebox" name="appid" data-options="missingMessage:'请输入小程序APPID',required:true"></td>
        </tr>
        <tr id="menu_pagepath_td">
            <td align="right"><label>小程序地址:</label></td>
            <td align="left"><input id="menu_pagepath_validatebox" class="easyui-validatebox" name="pagepath" data-options="missingMessage:'请输入小程序地址',required:true"></td>
        </tr>
    </table>

    <div  data-options="region:'south',border:false" style="height: 24px;text-align: center;position: absolute;bottom: 15px;width:100%" >
        <a  class="easyui-linkbutton" icon="icon-save" onclick="submitMenuInfo()">提交</a>
        <a  class="easyui-linkbutton" icon="icon-cancel" onclick="$('#menu_insert').dialog('close');" >取消</a>
    </div>
</form>

<script type="text/javascript">
    $(function () {
        $("#insert_manu_select").combotree({
            url : '${path }/wechat/public/number/menu/tree.do',
            parentField : 'pid',
            lines : true,
            panelHeight : 'auto',
            onLoadSuccess:function (value, date) {
                if (date.length <= 0) {
                    $("#insert_manu_select").combotree("setValue", '')
                    $("#insert_manu_select").combotree("setText", '无可选的上级菜单')
                }
            }
        })

        $("#select_menu_type").combobox({
            onSelect:function (value) {
                handleSelectShowView(value.value);
            }
        })

        handleSelectShowView("")
    })

    function handleSelectShowView(value) {

        switch (value) {
            case "": {
                showOrHidden(false, false, false, false, false, false);
                $('#insert_manu_select').combotree('clear');$('#insert_manu_select').combotree('setValue', '');
                $('#showCanSetSubMenu').text('可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "green ";//字体颜色
            } break;
            case "view": {
                showOrHidden(false, false, true, false, false, true);
                $('#showCanSetSubMenu').text('不可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "red ";//字体颜色
            } break;
            case "click": {
                showOrHidden(true, false, false, false, false, true);
                $('#showCanSetSubMenu').text('不可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "red ";//字体颜色
            } break;
            case "miniprogram": {
                showOrHidden(false, false, true, true, true, true);
                $('#showCanSetSubMenu').text('不可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "red ";//字体颜色
            } break;
            case "scancode_waitmsg": {
                showOrHidden(true, false, false, false, false, true);
                $('#showCanSetSubMenu').text('可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "green ";//字体颜色
            } break;
            case "scancode_push": {
                showOrHidden(true, false, false, false, false, true);
                $('#showCanSetSubMenu').text('可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "green ";//字体颜色
            } break;
            case "pic_sysphoto": {
                showOrHidden(true, false, false, false, false, true);
                $('#showCanSetSubMenu').text('可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "green ";//字体颜色
            } break;
            case "pic_photo_or_album": {
                showOrHidden(true, false, false, false, false, true);
                $('#showCanSetSubMenu').text('可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "green ";//字体颜色
            } break;
            case "pic_weixin": {
                showOrHidden(true, false, false, false, false, true);
                $('#showCanSetSubMenu').text('可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "green ";//字体颜色
            } break;
            case "location_select": {
                showOrHidden(true, false, false, false, false, true);
                $('#showCanSetSubMenu').text('不可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "red ";//字体颜色
            } break;
            case "media_id": {
                showOrHidden(false, true, false, false, false, true);
                $('#showCanSetSubMenu').text('不可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "red ";//字体颜色
            } break;
            case "view_limited": {
                showOrHidden(false, true, false, false, false, true);
                $('#showCanSetSubMenu').text('不可添加子菜单');
                document.getElementById('showCanSetSubMenu').style.color= "red ";//字体颜色
            } break;
        }
    }
    
    function showOrHidden(isShowKey, isShowMediaID, isShowUrl, isShowAppId, isShowPagepath, isShowParentid) {
        if (isShowKey) showView("menu_key_td", "menu_key_validatebox");
        else hiddenView("menu_key_td", "menu_key_validatebox");

        if (isShowMediaID) showView("menu_mediaId_td", "menu_mediaId_validatebox");
        else hiddenView("menu_mediaId_td", "menu_mediaId_validatebox");

        if (isShowUrl) showView("menu_url_td", "menu_url_validatebox");
        else hiddenView("menu_url_td", "menu_url_validatebox");

        if (isShowAppId) showView("menu_appid_td", "menu_appid_validatebox");
        else hiddenView("menu_appid_td", "menu_appid_validatebox");

        if (isShowPagepath) showView("menu_pagepath_td", "menu_pagepath_validatebox");
        else hiddenView("menu_pagepath_td", "menu_pagepath_validatebox");

        if (isShowParentid) $("#parent_menu_td").show();
        else $("#parent_menu_td").hide();
    }

    function showView(viewId, validateboxId) {
        $("#" + viewId).show();
        $("#" + validateboxId).validatebox({required: true});
    }

    function hiddenView(viewId, validateboxId) {
        $("#" + viewId).hide();
        $("#" + validateboxId).validatebox({required: false});
    }

    function submitMenuInfo() {
        lananUpdateOrInsertCombotree("添加", "${path}/wechat/public/number/menu/insert.do", "insertContentForm", "menu_insert", "wechatPublicMenuTreeGrid")
    }

</script>

</body>
</html>
